@extends('admin.main')

@section('content')
<div class="wrapper wrapper-content">
    <div class="ibox">
        <div class="ibox-title">
            <h5>编辑帮助</h5>
        </div>
        <div class="ibox-content">
            <form method="post" id="formInsert" class="form-horizontal" onsubmit="return false">
                <div class="form-group"><label class="col-sm-2 control-label">标题</label>
                    <div class="col-sm-8"><input type="text" class="form-control" name="title" placeholder="请输入标题" required="" value="{{$row->title}}"></div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="form-group "><label class="col-sm-2 control-label">内容</label>
                    <div class="col-sm-8">
                        <textarea id="ueditor_content" name="content" class="form-control" rows="10">{{$row->content}}</textarea>
                    </div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="form-group">
                    <div class="col-sm-4 col-sm-offset-2">
                        <input type="hidden" class="form-control" name="id" value="{{$row->id}}">
                        <button class="btn btn-primary" type="submit">提交</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

@endsection

@section('pageheader')

@endsection
@section('pagescript')
<!-- <script src="/assets/ueditor/ueditor.config.js"></script> -->
<!-- <script src="/assets/ueditor/ueditor.all.js"></script> -->
<script>
    $("#side-menu li[rel='help']").addClass("active");
    var filter = {page:1,status:0};
    var ueditor;
    $(function () {
        // ueditor = UE.getEditor('ueditor_content', {zIndex: 9});
        // ueditor.ready(function() {//编辑器初始化完成再赋值
        //     ueditor.setContent("{{$row->content}}",false);  //赋值给UEditor
        // });


        $("body").on("submit", "#formInsert", function(){
            var form = document.getElementById("formInsert");
            var formData = new FormData(form);
            $.ajax({
                url:"/admin/help/store",
                type:"post",
                data:formData,
                processData:false,
                contentType:false,
                success:function(data){
                    layer.msg('添加成功');
                    // window.location.reload();
                    if("{{$row->id}}"){
                        window.history.go(-1);
                    }else{
                        $('#formInsert')[0].reset();
                    }
                    ueditor.execCommand('cleardoc');
                },
                error:function(data){
                      var str = typeof(data) == 'string' ? data : data.responseJSON;
                      layer.msg(str, {icon:0});
                      return false;
                }
            });

            return false;
        });
    })

</script>
@endsection
